package com.github.coolcool.sloth.lianjiadb.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import com.github.coolcool.sloth.lianjiadb.mapper.HousepriceMapper;
import com.github.coolcool.sloth.lianjiadb.model.Houseprice;
import com.github.coolcool.sloth.lianjiadb.service.HousepriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.coolcool.sloth.lianjiadb.common.Page;
import javax.annotation.Generated;


@Generated(
	value = {
		"https://github.com/coolcooldee/sloth",
		"Sloth version:1.0"
	},
	comments = "This class is generated by Sloth"
)
@Service
public  class HousepriceServiceImpl implements HousepriceService{

	Logger logger = LoggerFactory.getLogger(HousepriceService.class);

	@Autowired
	private HousepriceMapper housepriceMapper;

	public Integer save(Houseprice houseprice){
		return housepriceMapper.insert(houseprice);
	}

	@Override
	public Houseprice getById(Object id){
		return housepriceMapper.getByPrimaryKey(id);
	}
	@Override
	public void deleteById(Object id){
		housepriceMapper.deleteByPrimaryKey(id);
	}
	@Override
	public void update(Houseprice houseprice){
		housepriceMapper.updateByPrimaryKey(houseprice);
	}

	@Override
	public Integer count(){
	    return housepriceMapper.count();
	}

	@Override
	public List<Houseprice> list(){
		return housepriceMapper.list();
	}

	@Override
	public Page<Houseprice> page(int pageNo, int pageSize) {
		Page<Houseprice> page = new Page<>();
        int start = (pageNo-1)*pageSize;
        page.setPageSize(pageSize);
        page.setStart(start);
        page.setResult(housepriceMapper.page(start,pageSize));
        page.setTotalCount(housepriceMapper.count());
        return page;
	}

	@Override
	public Integer increment(){
		return housepriceMapper.increment();
	}

	@Override
	public Houseprice getPrevious(String code){
		List<Houseprice> houseprices = housepriceMapper.listNewest(code);
		if(houseprices==null || houseprices.size()==0)
			return null;
		return houseprices.get(0);
	}

}